#include <iostream>
#include <unistd.h>
#include <sys/timerfd.h>

int main()
{
    int timerfd = timerfd_create(CLOCK_MONOTONIC, 0);
    if(timerfd < 0)
    {
        std::cerr << "timerfd create fail" << std::endl;
        return -1;
    }
    struct itimerspec itime;
    itime.it_value.tv_sec = 3; itime.it_value.tv_nsec = 0; 
    itime.it_interval.tv_sec = 2; itime.it_interval.tv_nsec = 0;
   
    timerfd_settime(timerfd, 0, &itime, nullptr);
    while(1)
    {
        uint64_t times;   //超时了多少次的统计
        int ret = read(timerfd, &itime, 8);
        if(ret < 0) return -1;
        //处理....
    }
    return 0;
}